#ifndef WEATHERPARSER_H_Q2C0CZT4
#define WEATHERPARSER_H_Q2C0CZT4

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include "../cglx.h"

using namespace std;

/*
 * Enumerated values for weather
 */

enum weather_t { SUNNY = 1,
                 CLOUDY = 2,
                 RAINY = 3,
                 ERROR = 99 };

class WeatherParser
{
private:
    const char *myDataFile;
    GLint temp;
    GLint weatherCode;

public:
    WeatherParser (const char *csv_file) {
        myDataFile = csv_file;
    }
    
    virtual ~WeatherParser () {}
    
    /* Returns termperature in Farenheit */
    GLint getTemp() {
        return temp;
    }
    
    GLint getWeatherCode() {
        return weatherCode;
    }
    
    weather_t getWeatherEnum() {
        readFromFile();
        return getWeatherFromYahooCode(weatherCode);
    }

private:
    void readFromFile() {
        ifstream data(myDataFile);
        string code, tem;
        
        getline(data, code);
        weatherCode = atoi(code.c_str());
        getline(data, tem);
        temp = atoi(tem.c_str());
        
        data.close();        
    }
    
    // Returns a weather_t enum given a Yahoo weather code
    // Yahoo weather codes from http://developer.yahoo.com/weather/#codes
    weather_t getWeatherFromYahooCode(GLint yahooCode) {
        if (yahooCode < 0 or yahooCode > 47) {
            return ERROR;
        } else if (yahooCode <= 17) { // This currently includes snow, hail, sleet
            return RAINY;
        } else if (yahooCode <= 28) {
            return CLOUDY;
        } else if (yahooCode <= 34 || yahooCode == 36) {
            return SUNNY;
        } else { // Remaining codes all some sort of thunderstorm i.e. 35, 37 - 47
            return RAINY;
        }
    }
};

#endif /* end of include guard: WEATHERPARSER_H_Q2C0CZT4 */
